import Mock from 'mockjs'
const Random = Mock.Random

let listData = function() {
  let _data = {
    status: 200,
    message: 'success',
    data: {
      total: 345,
      'rows|345': [{
        id: '@guid',
        title:'@ctitle(3,5)',
        name: '@cname',
        rate:'@integer(0,3)',
        avatar:"@image('200x100', '#50B347', '#FFF', 'EasyMock')",
        clickNum:'@integer(1000,9999)',
        switch : '@boolean',
        date:'@datetime',
        'state|1': ['deleted', 'published', 'draft'],
        address:Mock.mock('@county(true)'),
        house : '@integer(100,999)',
        paragraph:'@cparagraph(1)'
      }]
    }
  }
  return { _data }
}
// url为要拦截的请求地址  请求方式  请求数据（规则） （此处api会被mockjs拦截）
Mock.mock('http://route.showapi.com/60-27', 'get', listData())

let tableData = function() {
  let _data = {
    status: 200,
    message: 'success',
    data: {
      total: 159,
      'rows|159': [{
        id: '@guid',
        title:'@title(1)',
        name: '@cname',
        rate:'@integer(0,5)',
        clickNum:'@integer(300,9999)',
        switch : '@boolean',
        date:'@datetime',
        'state|1': [
          {
            'name|1':['热点', '头条'],
            label:['热点', '头条']
          }
        ],
        address:Mock.mock('@county(true)'),
        house : '@integer(100,999)',
        paragraph:'@cparagraph(1)',
      }]
    }
  }
  return { _data }
}
Mock.mock('http://route.showapi.com/70-27', 'get', tableData())

let ListData = function() {
  let _data = {
    status: 200,
    message: 'success',
    data: {
      total: 147,
      'rows|147': [{
        id: '@guid',
        title:'@title(2)',
        avatar:"@image('200x100', '#50B347', '#FFF', 'EasyMock')",
        name: '@cparagraph(1)',
        rate:'@integer(0,100)',
        date:'@datetime',
      }]
    }
  }
  return { _data }
}
Mock.mock('http://route.showapi.com/80-27', 'get', ListData())

let ExcelData = function() {
  let _data = {
    status: 200,
    message: 'success',
    data: {
      total: 20,
      'rows|20': [{
        id: '@guid',
        title:'@title(2)',
        clickNum:'@integer(300,9999)',
        name: '@cname',
        date:'@datetime',
        address:Mock.mock('@county(true)'),
      }]
    }
  }
  return { _data }
}
Mock.mock('http://route.showapi.com/90-27', 'get', ExcelData())

let roleData = function() {
  let _data = {
    status: 200,
    message: 'success',
    data: {
      total: 24,
      'rows|24': [{
        id: '@id()',
        password:'@guid',
        'username|1': ['admin', 'test', 'editor'],
        date:'@datetime',
        setting:'@shuffle(["读","写","删"], 2, 3)',
        email: '@email(qq.com)',
        "role":'@shuffle(["admin","editor"], 1, 2)'
      }]
    }
  }
  return { _data }
}
Mock.mock('http://route.showapi.com/100-27', 'get', roleData())

let systemData = function() {
  let _data = {
    status: 200,
    message: 'success',
    data: {
      total: 67,
      'rows|67': [{
        'type|1': ['数据库日志', '操作日志', '系统日志'],
        'user|1': ['test', 'editor', 'admin'],
        'result|1': ['接口异常', 'dos攻击', '登录成功','登录失败'],
        ip:'@ip()',
        date:'@datetime',
      }]
    }
  }
  return { _data }
}
Mock.mock('http://route.showapi.com/110-27', 'get', systemData())
